
export function downloadArrayBuffer(buffer: ArrayBuffer, type: string, filename: string) {
  const blob = new Blob([buffer], { type });
  downloadBlob(blob, filename);
}

export function downloadFile(file: File) {
  downloadBlob(file, file.name);
}

export function downloadBlob(blob: Blob, filename: string) {
  const linkAddress = URL.createObjectURL(blob);
  downloadLinkFile(linkAddress, filename);
  URL.revokeObjectURL(linkAddress);
}

export function downloadLinkFile(address: string, filename: string) {
  window.open(address, "_blank");
}


export function arrayBufferToBlob(buffer: ArrayBuffer, type: string) {
  return new Blob([buffer], { type });
}

export function arrayBufferToFile(buffer: ArrayBuffer, type: string, filename: string) {
  return blobToFile(arrayBufferToBlob(buffer, type), filename);
}

export function blobToFile(blob: Blob, filename: string) {
  return new File([blob], filename);
}
